<%@ page contentType="text/html; charset=UTF-8" pageEncoding="UTF-8" %>
<%@ taglib uri="/WEB-INF/struts-html" prefix="html" %>
<html:html>
<head>
	<title></title>
	
	<link rel="stylesheet" type="text/css" href="<%= request.getContextPath() %>/css/sampleForm.css" />
	<link rel="stylesheet" type="text/css" href="<%= request.getContextPath() %>/css/me.css" />	
	<link rel="stylesheet" type="text/css" href="<%= request.getContextPath() %>/common/css/help/help.css" />

  	<script type='text/javascript' src='/ittl/dwr/interface/BCAPInvoiceService2.js'></script>  	
  	
  	<script type='text/javascript' src='/ittl/dwr/engine.js'></script>
  	<script type='text/javascript' src='/ittl/dwr/util.js'></script>
  		
	<script type='text/javascript' src='<%= request.getContextPath() %>/css/autocomplete/lib/jquery.js' ></script>  	 	
	
	<link type="text/css" href="<%= request.getContextPath() %>/css/datepicker/css/ui.all.css" rel="stylesheet" /> 	
	<script type="text/javascript" src="<%= request.getContextPath() %>/css/datepicker/lib/jquery-ui-1.5.3.min.js"></script>	
	
	<script type="text/javascript">
		$(document).ready(function(){									
    			$("#startDate_taxBuy").datepicker({ altField: 'input#startDate_taxBuy', altFormat: 'dd-mm-yy' });    			
    			$("#endDate_taxBuy").datepicker({ altField: 'input#endDate_taxBuy', altFormat: 'dd-mm-yy' });
    			
    			$("#startDate_materialsInStock").datepicker({ altField: 'input#startDate_materialsInStock', altFormat: 'dd-mm-yy' });
    			$("#endDate_materialsInStock").datepicker({ altField: 'input#endDate_materialsInStock', altFormat: 'dd-mm-yy' });
    			
    			$("#startDate_purchasingMaterials").datepicker({ altField: 'input#startDate_purchasingMaterials', altFormat: 'dd-mm-yy' });
    			$("#endDate_purchasingMaterials").datepicker({ altField: 'input#endDate_purchasingMaterials', altFormat: 'dd-mm-yy' });

    			$("#startDate_dyestuffsChemicals").datepicker({ altField: 'input#startDate_dyestuffsChemicals', altFormat: 'dd-mm-yy' });
    			$("#endDate_dyestuffsChemicals").datepicker({ altField: 'input#endDate_dyestuffsChemicals', altFormat: 'dd-mm-yy' });
  		});
	</script>		
	<script type="text/javascript">
		function validate(startDate, endDate) {
			var valid = true;
/*			if(document.getElementById(startDate).value!="" ) {
				document.getElementById(startDate+"_error").innerHTML = "";
			}else {
				document.getElementById(startDate+"_error").innerHTML = "วันที่ไม่ถูกต้อง";
				valid = false;								
			}				 

			if(document.getElementById(endDate).value !="" ) {				
				document.getElementById(endDate+"_error").innerHTML = "";							
			}else {				
				document.getElementById(endDate+"_error").innerHTML = "วันที่ไม่ถูกต้อง";
				valid = false;				
			}				 			

			if(valid) {
			valid = check_startDate_endDate(startDate, endDate);
			}*/
			return valid;
		}

		function check_startDate_endDate(startDate, endDate) {
			var start_date = new Date(document.getElementById(startDate).value);
			var end_date = new Date(document.getElementById(endDate).value);

			if(start_date>end_date) {
				document.getElementById(startDate+"_error").innerHTML = "วันที่เริ่มต้น มากกว่า วันที่สิ้นสุด";
				document.getElementById(endDate+"_error").innerHTML = "";
				return false;
			}else {
				document.getElementById(startDate+"_error").innerHTML = "";
				document.getElementById(endDate+"_error").innerHTML = "";				
				return true;
			}
		}
		
	</script>
<script type="text/javascript" >

function modalWinItem(aa) {
	if (window.showModalDialog) {		
		window.showModalDialog(aa,"name","dialogTop:100px;dialogWidth:650px;dialogHeight:350px;center:yes");
	} else {		
		window.open(aa,'name','height=350,width=600,toolbar=no,directories=no,status=no,continued from previous linemenubar=no,scrollbars=no,resizable=no ,modal=yes');
	}
}
</script>

<!--  ส่วนที่ 2 -->
<script language="JavaScript">
var var1=0;
var sumOfItemAmount=0;
var taxAmount = 0;
var totalAmount  =0;
function getBCAPInvoice(id2) {
	var1=id2;
	//BCAPInvoiceService2 เป็นชื่อ javascript ที่ อยู่ใน dwr xml ไว้สำหรับอ้างไปที่ java 
	if(document.getElementById("docNo"+id2).value!="") {
		document.getElementById("docNo"+id2).value = document.getElementById("docNo"+id2).value.toUpperCase();
		BCAPInvoiceService2.getBCAPInvoice( document.getElementById("docNo"+id2).value, loadinfoAPInvoice );
	}			  
}

//<!--  ส่วนที่ 3 -->
function loadinfoAPInvoice(bCAPInvoice){
	
	if(bCAPInvoice.sumOfItemAmount!=null) {
		docNo = document.getElementById("docNo"+var1).value;
		items 			= bCAPInvoice.numOfItem;
		sumOfItemAmount = sumOfItemAmount*1+ bCAPInvoice.sumOfItemAmount*1;
		taxAmount       = taxAmount*1+ bCAPInvoice.taxAmount*1;
		totalAmount     = totalAmount*1+ bCAPInvoice.totalAmount*1;

		
		dwr.util.setValue("items"+var1, items);
		//alert(docNo.substr(0,1));
		if(docNo.substr(0,1)=="C" ) {
			
			dwr.util.setValue("cash"+var1, "");
			dwr.util.setValue("sumOfItemAmount"+var1, bCAPInvoice.sumOfItemAmount.toFixed(2));

		}else if(docNo.substr(0,1)=="B" ) {
			dwr.util.setValue("cash"+var1, bCAPInvoice.sumOfItemAmount.toFixed(2));
			dwr.util.setValue("sumOfItemAmount"+var1, "");
			
		}
		dwr.util.setValue("taxAmount"+var1, bCAPInvoice.taxAmount.toFixed(2));
		dwr.util.setValue("totalAmount"+var1, bCAPInvoice.totalAmount.toFixed(2));
		dwr.util.setValue("type"+var1, bCAPInvoice.remark2);			

	}else {
		alert("ไม่พบ :"+document.getElementById("docNo"+var1).value+" \n\n\nกรุณาตรวจสอบเลขที่เอกสารอีกครั้ง");
		//document.getElementById("apCode").focus();
		dwr.util.setValue("sumOfItemAmount", "");
	}				     
}
</script>
		
</head>
<body>
<div id="wrapper">
	 
	<div id="menu"><ul id="nav"></ul></div>

	<div id="content">
		<div id="menuNav"><a href='<%=request.getContextPath() %>/Login.do?mode=check'>หน้าหลัก</a> 
		>> คลังพัสดุ-Store กลาง >> จัดซื้อ >> 6.บันทึกใบส่งคืนสินค้า/ลดหนี้ </div><br />
		<p align="center" id="titleIssueType">บันทึกใบส่งคืนสินค้า/ลดหนี้ </p>
		<div id="userPw01">
		<fieldset>
			<legend><b>ค้นหา: ใบสำคัญ การจัดซื้อ, การชำระเงิน </b></legend>
			   <center><br />
	    		<html:form action="/invfind.do?mode=findInvSelected"  >
		    	<table border="1">
		    		<tr>
		    			<td align="center" width="150">เลขที่เอกสาร Invoice:</td>
		    			<td align="center" width="150">Items</td>
		    			<td width="100">
		    				<a href="#" target="name" onclick="modalWinItem('/ittl/apinvoice/printinv.do?mode=invFind&lineNumber=1'); return false;">
		    					<img src="../images/Find2.bmp"></a>
		    			</td>
		    		</tr>
		    		<tr>
		    			<td align="right"width="50">
		    				<input type='text' name='docNoArray' id='docNo1' style="width:200px;height:40px" onblur="getBCAPInvoice(1);" onchange="getBCAPInvoice(1);"  >

		    			</td>
		    			<td align="center"><div align="center" id="items1"></div></td>
		    			
		    			<td ><html:submit value="ตกลง" onclick="return validate('docNo1','test');" style="width:100px;height:40px"  /></td>	    			
		    		</tr>
		    		
		    				    				    				   		    		
		    	</table>
	    		</html:form>
	    	</center>
	    </fieldset>
	    </div>
				  			    		
	    	    
    </div>
</div>
</body>
</html:html>
